package xml;

import org.jdom2.*;
import org.jdom2.output.*;
import org.junit.Test;

import io.TestResourcesDirectory;

import java.io.*;

/**
 * jdom演示
 * @author fidel
 */
public class CustomDemo {
    @Test
    public void main() throws IOException {
        Element root = new Element("root");
        Document document = new Document(root);
        root.addContent(new Element("child1").setAttribute("attr1", "attr1-value"));
        Element child2 = new Element("child2");
        root.addContent(child2.setAttribute("attr2", "attr2-value"));
        child2.addContent(new Element("child3").setText("child3-text"));
        File file = new File(TestResourcesDirectory.PATH + File.separator + "demo.xml");
        FileWriter writer = new FileWriter(file);
        XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat());
        outputter.output(document, writer);
    }
}
